import 'package:permission_handler/permission_handler.dart';

class PermissionUtil {
  PermissionUtil._();

  ///请求<定位>权限
  static Future<bool> location() async {
    if (await Permission.location.request().isGranted) {
      return true;
    } else {
      openAppSettings();
      return false;
    }
  }

  ///请求<读外部存储>权限
  static Future<bool> storage() async {
    if (await Permission.storage.request().isGranted) {
      return true;
    } else {
      openAppSettings();
      return false;
    }
  }

  ///请求<联系人>权限
  static Future<bool> contacts() async {
    if (await Permission.contacts.request().isGranted) {
      return true;
    } else {
      openAppSettings();
      return false;
    }
  }

  ///请求<麦克风>权限
  static Future<bool> microphone() async {
    if (await Permission.microphone.request().isGranted) {
      return true;
    } else {
      openAppSettings();
      return false;
    }
  }
}
